import { defineStore } from "pinia"
import { GoodsInfo } from "@/types/goods"
import { getGoodsInfo } from "@/api/goods";

export default defineStore('goods', {
  state: () => {
    return {
      goodsInfo: {} as GoodsInfo,
    }
  },
  actions: {
    // 获取商品详情数据 
    async loadGoodsInfo (id: string) {
      const res = await getGoodsInfo({ id })
      this.goodsInfo = res.data.result
    },
    // 清空商品详情数据 
    resetGoodsInfo () {
      this.goodsInfo = {} as GoodsInfo
    }
  }
})